package com.elem.test;

import java.lang.reflect.Method;

public class ClassDemo04 {
    public static void main(String[] args) throws Exception {

        // 1. 通过Class类的静态方法forName()
        Class accountClass = Class.forName("com.neuedu.elem.test.Account");

        Object obj = accountClass.newInstance();
        // 2. 获取所有的公共方法
//        Method[] methods = accountClass.getMethods();
//        Method[] methods = accountClass.getDeclaredMethods();
//        for (Method method : methods) {
//            System.out.println(method);
//        }

//        Method showInfoMethod = accountClass.getMethod("showInfo", String.class, double.class);
////        System.out.println(showInfoMethod);
//
//        // invoke方法的返回值，就是该方法的执行结果
//        Object object = showInfoMethod.invoke(obj, "Tom", 10000);
//        System.out.println(object);

        Method sumMethod = accountClass.getMethod("sum", int.class, int.class);
        Object object = sumMethod.invoke(obj, 100, 10000);
        System.out.println("object = " + object);
    }
}
